<?php

/**
 * This is the model class for table "ruangan".
 *
 * The followings are the available columns in table 'ruangan':
 * @property integer $id
 * @property integer $floor_id
 * @property integer $user_id
 * @property integer $type_ruangan_id
 * @property string $name
 * @property integer $capacity
 * @property double $rx
 * @property double $ry
 * @property double $rw
 * @property double $rh
 *
 * The followings are the available model relations:
 * @property Rapat[] $rapats
 * @property Floor $floor
 * @property TypeRuangan $typeRuangan
 */
class Ruangan extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Ruangan the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ruangan';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('floor_id, rx, ry, rw, rh', 'required'),
			array('floor_id, user_id, type_ruangan_id, capacity', 'numerical', 'integerOnly'=>true),
			array('rx, ry, rw, rh', 'numerical'),
			array('name', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, floor_id, user_id, type_ruangan_id, name, capacity, rx, ry, rw, rh', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rapats' => array(self::HAS_MANY, 'Rapat', 'room_id'),
			'floor' => array(self::BELONGS_TO, 'Floor', 'floor_id'),
			'typeRuangan' => array(self::BELONGS_TO, 'TypeRuangan', 'type_ruangan_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'floor_id' => 'Lantai',
			'user_id' => 'Pemilik',
			'type_ruangan_id' => 'Jenis Ruangan',
			'name' => 'Nama Ruangan',
			'capacity' => 'Kapasitas',
			'rx' => 'Rx',
			'ry' => 'Ry',
			'rw' => 'Rw',
			'rh' => 'Rh',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('floor_id',$this->floor_id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('type_ruangan_id',$this->type_ruangan_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('capacity',$this->capacity);
		$criteria->compare('rx',$this->rx);
		$criteria->compare('ry',$this->ry);
		$criteria->compare('rw',$this->rw);
		$criteria->compare('rh',$this->rh);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}